//Libreria ITpp


00035 void Turbo_Codec::set_parameters(ivec gen1, ivec gen2, int constraint_length, const ivec &interleaver_sequence,
00036                                  int in_iterations, std::string in_metric, double in_logmax_scale_factor,
00037                                  bool in_adaptive_stop,  LLR_calc_unit in_llrcalc)
00038 {
00039   //Set the input parameters:
00040   iterations          = in_iterations;
00041   interleaver_size    = interleaver_sequence.size();
00042   Nuncoded            = interleaver_size;
00043   logmax_scale_factor = in_logmax_scale_factor;
00044   adaptive_stop       = in_adaptive_stop;
00045 
00046   //Check the decoding metric
00047   if (in_metric == "LOGMAX") {
00048     metric = "LOGMAX";
00049   }
00050   else if (in_metric == "LOGMAP") {
00051     metric = "LOGMAP";
00052   }
00053   else if (in_metric == "MAP") {
00054     metric = "MAP";
00055   }
00056   else if (in_metric == "TABLE") {
00057     metric = "TABLE";
00058   }
00059   else {
00060     it_error("Turbo_Codec::set_parameters: The decoder metric must be either MAP, LOGMAP or LOGMAX");
00061   }
00062 
00063   if (logmax_scale_factor != 1.0) {
00064     it_assert(metric == "LOGMAX", "Turbo_Codec::set_parameters: logmax_scale_factor can only be used together with LOGMAX decoding");
00065   }
00066 
00067   //The RSC Encoders:
00068   rscc1.set_generator_polynomials(gen1, constraint_length);
00069   rscc2.set_generator_polynomials(gen2, constraint_length);
00070   n1 = gen1.length() - 1; //Number of parity bits from rscc1
00071   n2 = gen2.length() - 1; //Number of parity bits from rscc2
00072   n_tot = 1 + n1 + n2;  //Total number of parity bits and systematic bits
00073 
00074   //Set the number of tail bits:
00075   m_tail = constraint_length - 1;
00076 
00077   //Calculate the number of coded bits per code-block:
00078   Ncoded = Nuncoded * n_tot + m_tail * (1 + n1) + m_tail * (1 + n2);
00079 
00080   //Set the interleaver sequence
00081   bit_interleaver.set_interleaver_depth(interleaver_size);
00082   float_interleaver.set_interleaver_depth(interleaver_size);
00083   bit_interleaver.set_interleaver_sequence(interleaver_sequence);
00084   float_interleaver.set_interleaver_sequence(interleaver_sequence);
00085 
00086   //Default value of the channel reliability scaling factor is 1
00087   Lc = 1.0;
00088 
00089   // LLR algebra table
00090   rscc1.set_llrcalc(in_llrcalc);
00091   rscc2.set_llrcalc(in_llrcalc);
00092 
00093 }



00068 // --------------- Public functions -------------------------
00069 void Rec_Syst_Conv_Code::set_generator_polynomials(const ivec &gen, int constraint_length)
00070 {
00071   int j;
00072   gen_pol = gen;
00073   n = gen.size();
00074   K = constraint_length;
00075   m = K - 1;
00076   rate = 1.0 / n;
00077 
00078   gen_pol_rev.set_size(n, false);
00079   for (int i = 0; i < n; i++) {
00080     gen_pol_rev(i) = reverse_int(K, gen_pol(i));
00081   }
00082 
00083   Nstates = (1 << m);
00084   state_trans.set_size(Nstates, 2, false);
00085   rev_state_trans.set_size(Nstates, 2, false);
00086   output_parity.set_size(Nstates, 2*(n - 1), false);
00087   rev_output_parity.set_size(Nstates, 2*(n - 1), false);
00088   int s0, s1, s_prim;
00089   ivec p0, p1;
00090   for (s_prim = 0; s_prim < Nstates; s_prim++) {
00091     s0 = calc_state_transition(s_prim, 0, p0);
00092     state_trans(s_prim, 0) = s0;
00093     rev_state_trans(s0, 0) = s_prim;
00094     for (j = 0; j < (n - 1); j++) {
00095       output_parity(s_prim, 2*j + 0) = p0(j);
00096       rev_output_parity(s0, 2*j + 0) = p0(j);
00097     }
00098 
00099     s1 = calc_state_transition(s_prim, 1, p1);
00100     state_trans(s_prim, 1) = s1;
00101     rev_state_trans(s1, 1) = s_prim;
00102     for (j = 0; j < (n - 1); j++) {
00103       output_parity(s_prim, 2*j + 1) = p1(j);
00104       rev_output_parity(s1, 2*j + 1) = p1(j);
00105     }
00106   }
00107 
00108   ln2 = std::log(2.0);
00109 
00110   //The default value of Lc is 1:
00111   Lc = 1.0;
00112 }




